package data_structures_and_algorithms.tree;

import common.TreeNode;

/**
 * @ClassName Code_0101_isSymmetric
 * @Description: 101. 对称二叉树
 *
 * https://leetcode.cn/problems/symmetric-tree/
 * @Author: yongliang.ma
 * @Create_time:2022/10/26 21:52
 */
public class Code_0101_isSymmetric {

    public boolean isSymmetric(TreeNode root) {
        if (root == null)
            return true;

        return dfs(root.left, root.right);
    }

    public boolean dfs(TreeNode L, TreeNode R){
        if (L == null && R == null)
            return true;
        if (L == null ^ R == null)
            return false;

        // 判断 二者是否想等
        if (L.val != R.val)
            return false;

        return dfs(L.left, R.right) && dfs(L.right, R.left);
    }
}
